﻿using System;
using System.Collections.Generic;
using System.Text;
using Model;
using System.Data;
using SqlServerDAL;

namespace BLL
{
    public class ViolationBLL
    {
      private readonly ViolationDAL dal=new ViolationDAL();

		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			return dal.Exists(ID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(Violation model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Violation model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			return dal.Delete(ID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			return dal.DeleteList(IDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Violation GetModel(int ID)
		{
			
			return dal.GetModel(ID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
        //public Violation GetModelByCache(int ID)
        //{
			
        //    string CacheKey = "ViolationModel-" + ID;
        //    object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = dal.GetModel(ID);
        //            if (objModel != null)
        //            {
        //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch{}
        //    }
        //    return (Violation)objModel;
        //}

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetOrganList(int organID)
        {
            string strWhere = "A.OrganID = " + organID;
            return dal.GetList(strWhere);
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Violation> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Violation> DataTableToList(DataTable dt)
		{
			List<Violation> modelList = new List<Violation>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Violation model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Violation();
					if(dt.Rows[n]["ID"]!=null && dt.Rows[n]["ID"].ToString()!="")
					{
						model.ID=int.Parse(dt.Rows[n]["ID"].ToString());
					}
					if(dt.Rows[n]["FrameNO"]!=null && dt.Rows[n]["FrameNO"].ToString()!="")
					{
					model.FrameNO=dt.Rows[n]["FrameNO"].ToString();
					}
					if(dt.Rows[n]["Driver"]!=null && dt.Rows[n]["Driver"].ToString()!="")
					{
					model.Driver=dt.Rows[n]["Driver"].ToString();
					}
					if(dt.Rows[n]["ViolationTime"]!=null && dt.Rows[n]["ViolationTime"].ToString()!="")
					{
						model.ViolationTime=DateTime.Parse(dt.Rows[n]["ViolationTime"].ToString());
					}
					if(dt.Rows[n]["ViolationAddress"]!=null && dt.Rows[n]["ViolationAddress"].ToString()!="")
					{
					model.ViolationAddress=dt.Rows[n]["ViolationAddress"].ToString();
					}
                    if (dt.Rows[n]["ViolationAct"] != null && dt.Rows[n]["ViolationAct"].ToString() != "")
					{
                        model.ViolationAct = dt.Rows[n]["ViolationAct"].ToString();
					}
					if(dt.Rows[n]["FineMoney"]!=null && dt.Rows[n]["FineMoney"].ToString()!="")
					{
						model.FineMoney=decimal.Parse(dt.Rows[n]["FineMoney"].ToString());
					}
                    if (dt.Rows[n]["LateFee"] != null && dt.Rows[n]["LateFee"].ToString() != "")
                    {
                        model.LateFee = decimal.Parse(dt.Rows[n]["LateFee"].ToString());
                    }
					if(dt.Rows[n]["NoticeTime"]!=null && dt.Rows[n]["NoticeTime"].ToString()!="")
					{
						model.NoticeTime=DateTime.Parse(dt.Rows[n]["NoticeTime"].ToString());
					}
					if(dt.Rows[n]["DealStatus"]!=null && dt.Rows[n]["DealStatus"].ToString()!="")
					{
					model.DealStatus=dt.Rows[n]["DealStatus"].ToString();
					}
					if(dt.Rows[n]["DealTime"]!=null && dt.Rows[n]["DealTime"].ToString()!="")
					{
						model.DealTime=DateTime.Parse(dt.Rows[n]["DealTime"].ToString());
					}
					if(dt.Rows[n]["Remark"]!=null && dt.Rows[n]["Remark"].ToString()!="")
					{
					model.Remark=dt.Rows[n]["Remark"].ToString();
					}
					if(dt.Rows[n]["OrganID"]!=null && dt.Rows[n]["OrganID"].ToString()!="")
					{
						model.OrganID=int.Parse(dt.Rows[n]["OrganID"].ToString());
					}
                    if (dt.Rows[n]["VehicleID"] != null && dt.Rows[n]["VehicleID"].ToString() != "")
                    {
                        model.VehicleID = dt.Rows[n]["VehicleID"].ToString();
                    }
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
    }
}
